# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Jürgen Pfeifer <juergen@familiepfeifer.de>

_realname=db

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.0.30
pkgrel=1
pkgdesc="The Berkeley DB embedded database system (mingw-w64)"
arch=('any')
url="http://www.oracle.com/technology/software/products/berkeley-db/index.html"
license=('custom')
groups=("${MINGW_PACKAGE_PREFIX}")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=(http://download.oracle.com/berkeley-db/db-${pkgver}.tar.gz
    mingw.patch)
sha1sums=('038dca3ef2984c6cb95ff088d1ab7c7b9da40883'
          '9cb5319029744f6e5d571d0ade25b6ea62e2958f')

prepare()
{
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/mingw.patch
}

build() {
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}
  ../${_realname}-${pkgver}/dist/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-compat185 \
    --enable-mingw \
    --enable-shared \
    --enable-static \
    --disable-rpath \
    --enable-cxx \
    --enable-sql \
    --enable-sql-codegen \
    --enable-stl \
    --enable-dbm \
    --disable-tcl \
    --disable-replication \
    --docdir='${prefix}/share/doc/db'
  make LIBSO_LIBS=-lpthread
}

check() {
  cd ${srcdir}/build-${CARCH}
  make cutest
  if [ -x ./cutest.exe ]; then
    ./cutest.exe || true
  fi
}

package() {
  cd ${srcdir}/build-${CARCH}
  make DESTDIR="${pkgdir}" install
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname  
  cp -pf ${srcdir}/${_realname}-${pkgver}/LICENSE \
    ${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname
}
